package net.uiiang.android.alkaid.helper;

import java.util.ArrayList;
import java.util.List;

import net.uiiang.android.alkaid.object.FileItem;
import net.uiiang.android.alkaid.object.FileView;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class EfficientAdapter extends ArrayAdapter<Object> {
    private List<FileItem> mItems = new ArrayList<FileItem>();
    // private FileItem fileItem;
    // private LayoutInflater mInflater;
    private final Context context;
    private boolean mutipleSelect = false;

    public EfficientAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        // mInflater = (LayoutInflater) context
        // .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
    }

    public EfficientAdapter(Context context, int textViewResourceId,
            boolean mutipleSelect) {
        super(context, textViewResourceId);
        this.mutipleSelect = mutipleSelect;
        // mInflater = (LayoutInflater) context
        // .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
    }

    public void addItem(FileItem it) {
        mItems.add(it);
    }

    public void setListItems(List<FileItem> lit) {
        mItems = lit;
    }

    public int getCount() {
        return mItems.size();
    }

    public Object getItem(int position) {
        return mItems.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    // public View getView(int position, View convertView, ViewGroup parent) {
    // FileView btv;
    // btv = new FileView(mContext, mItems.get(position));
    // return btv;
    // }
    public View getView(int position, View convertView, ViewGroup parent) {
        // FileView btv;
        // btv = new FileView();
        // setContentView(android.R.layout.simple_list_item_multiple_choice);
        // convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
        // fileItem = (FileItem) this.getItem(position);
        // ((TextView) convertView.findViewById(R.id.title))
        // .setText(fileItem.getTitle());
        // ((ImageView) convertView.findViewById(R.id.icon))
        // .setImageDrawable(((FileItem) this.getItem(position)).getIcon());
        // ((TextView) convertView.findViewById(R.id.desc))
        // .setText(fileItem.getDesc());
        // CheckBox checkBox = ((CheckBox)
        // convertView.findViewById(R.id.check));
        // checkBox.setChecked(fileItem.isChecked());
        // checkBox.setOnClickListener(new OnClickListener(){
        // public void onClick(View v) {
        // // fileItem.setChecked(getCheckBoxState());
        // }
        // });
        // btv.getTitle().setText(((FileItem)
        // this.getItem(position)).getTitle());
        // btv.getDesc().setText(((FileItem) this.getItem(position)).getDesc());
        // btv.getIcon().setImageDrawable(
        // ((FileItem) this.getItem(position)).getIcon());
        // btv.setCheckBox((CheckBox)convertView.findViewById(R.id.check));
        // System.out.println("check box = "+btv.getCheckBox().getId());
        // btv.getCheckBox().setChecked(true);
        // return convertView;
        FileView fView = new FileView();
        return fView.newFileView(this.context, (FileItem) this
                .getItem(position),mutipleSelect);

    }

}
